package com.huai.demo_test1.singletionsecond.hungry;import java.io.Serializable;/** * 饿汉式单例模式：类一加载就创建对象，但容易产生垃圾对象，浪费内存空间。 * 优点：线程安全，没有加锁，执行效率较高 * 缺点：不是懒加载，类加载时就初始化，浪费内存空间 */public class HungrySingleton implements Serializable {    private final static HungrySingleton hungrySingleton;    static {        hungrySingleton = new HungrySingleton();    }    private HungrySingleton() {    }    public static HungrySingleton getInstance() {        return hungrySingleton;    }}